# -*- coding:utf-8 -*-
"""
Python 3.7
Author：何若溥
Time：2023/07/26
"""

from common.dingUtil import sendDing
from common.fileUtil import getBugUrl
from dataProcess.chartData import getDataCollect


def cwReport(project_id, ding_access_token, header):
    # 项目bug 禅道 url地址
    bug_url = getBugUrl(project_id)

    # 获取今日新增bug、今日解决bug、剩余未解决bug及列表图片
    data_collect = getDataCollect(project_id)
    chart_urls = data_collect.get("urls")
    print(chart_urls)
    td_data = data_collect.get("tdBug")

    data = {
        "msgtype": "markdown",
        "markdown": {
            "title": "云仓Bug日报",
            "text": "# <font face=\"Helvetica\" color=\"#660000\">云仓今日Bug情况如下:</font>\n"
                    f"* **<font face=\"Helvetica\" color=\"#dd0000\">今日新增问题 {td_data[0]} 个</font>**\n"
                    f"* **<font face=\"Helvetica\" color=\"#00dd00\">今日解决问题 {td_data[1]} 个</font>**\n"
                    f"* **<font face=\"Helvetica\" color=\"#0000dd\">剩余未解决问题 {td_data[2]} 个，见下表:</font>**\n"	
                    f"![]({chart_urls[0]})\n"
                    "# <font face=\"Helvetica\" color=\"#660000\">未修复bug分布如下，请相关人员抓紧时间处理问题:</font>\n"
                    # f"![]({chart_urls[1]})"
                    f"![]({chart_urls[2]})\n"
                    f"![]({chart_urls[3]})\n"
                    f"##### [点击查看禅道Bug列表]({bug_url})\n",
            "at": {
                "isAtAll": True
            }
        }
    }

    sendDing(ding_access_token, data, header)
